﻿namespace jzgl.Controller
{
    using jzgl.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Windows.Forms;

    public class BudgetInfoDB
    {
        private SqlConnection conn = null;
        private ConnDB conndb = new ConnDB();
        private DataTable table = null;

        public BudgetInfoDB()
        {
            this.conn = this.conndb.GetConnString();
        }

        public int Add_BudgetInfo(BudgetInfo b)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = string.Concat(new object[] { "insert into BudgetInfo (BudInfoNodeId,BudInfoName,BudInfoPrice,BudInfoRemark,BudListKey)  values('", b.BudInfoNodeId, "','", b._BudInfoName, "','", b._BudInfoPrice, "','", b._BudInfoRemark, "','", b._BudListKey, "')" });
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            finally
            {
            }
            return num;
        }

        public int Delete_BudgetInfo(BudgetInfo b)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "delete from BudgetInfo where BudInfoId='" + b._BudInfoId + "'";
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }

        public int Delete_BudgetInfoBYBudgetList_Key(string listKey)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = "delete from BudgetInfo where  BudListKey='" + listKey + "'";
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }

        public DataTable Show_BudgetInfo()
        {
            try
            {
                try
                {
                    string sql = "select * from BudgetInfo";
                    this.table = this.conndb.FillDataTable(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return this.table;
        }

        public void Show_BudgetInfo(DataGridView dgv)
        {
            try
            {
                try
                {
                    string sqlstr = "select * from BudgetList";
                    this.conndb.dgvDataBind(dgv, sqlstr);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
        }

        public DataTable Show_BudgetInfoBYBudgetList_Key(string listId)
        {
            try
            {
                try
                {
                    string sql = "select * from BudgetInfo where BudListKey='" + listId + "'";
                    this.table = this.conndb.FillDataTable(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return this.table;
        }

        public int Update_BudgetInfo_Name(BudgetInfo b)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = string.Concat(new object[] { "update BudgetInfo set BudInfoName='", b._BudInfoName, "' where BudInfoId='", b._BudInfoId, "'" });
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }

        public int Update_BudgetInfo_Price(BudgetInfo b)
        {
            int num = 0;
            try
            {
                try
                {
                    string sql = string.Concat(new object[] { "update BudgetInfo set BudInfoPrice='", b._BudInfoPrice, "'   where BudInfoId='", b._BudInfoId, "'" });
                    num = this.conndb.Execute_Sql(sql);
                }
                catch (Exception)
                {
                }
            }
            finally
            {
            }
            return num;
        }
    }
}

